package playn.platformer;

import java.util.HashMap;

import com.allen_sauer.gwt.log.client.Log;

import playn.core.Image;
import playn.core.ImmediateLayer;
import playn.core.Surface;
import tiled.simple.core.Renderer;

public class DynamicRenderer  implements Renderer,ImmediateLayer.Renderer{

	private HashMap<String,Image> imagesCache = new HashMap<String, Image>();

	private MapObjectsProvider mapObjectsProvider;
	
	public DynamicRenderer(MapObjectsProvider mapObjectsProvider,HashMap<String,Image> imagesCache){
		this.imagesCache=imagesCache;
		this.mapObjectsProvider=mapObjectsProvider;
	}

	public void putImage(String source, int sx, int sy, int sw, int sh, int dx,int dy, int dw, int dh) {
		
			if(!imagesCache.containsKey(source)){
				Log.error("you have to load "+source+" image from loader using imagesCache");
			}
			
			Image img=imagesCache.get(source);

			if((img!=null)&&(surface!=null)){
				surface.drawImage(img, dx, dy, dw, dh, sx, sy, sw, sh);
			}
	}

	Surface surface=null;
	
	public void render(Surface surface) {
		this.surface=surface;
		mapObjectsProvider.render();
	}

}
